/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.translog.gui.entradaentrega;

import br.com.translog.fachada.FachadaTranslog;
import br.com.translog.gui.outro.FrmMenuPrincipal;
import br.com.translog.modelo.EntradaEntrega;
import br.com.translog.modelo.Logradouro;
import br.com.translog.modelo.VolumeEntrega;
import java.util.Date;
import javax.swing.JOptionPane;

/**
 *
 * @author Henrique
 */
public class FrmEntradaEntregaConsultar extends javax.swing.JFrame {

    EntradaEntrega ee;

    /**
     * Creates new form FrmEntradaEntregaAlterar
     */
    public FrmEntradaEntregaConsultar() {
        initComponents();
        setLocationRelativeTo(null);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblCodigoCliente1 = new javax.swing.JLabel();
        btnCancelar = new javax.swing.JButton();
        lblCEP1 = new javax.swing.JLabel();
        btnPesquisar = new javax.swing.JButton();
        lblNumero1 = new javax.swing.JLabel();
        lblEstado1 = new javax.swing.JLabel();
        lblCidade1 = new javax.swing.JLabel();
        txtNumero = new javax.swing.JTextField();
        txtCodigo = new javax.swing.JTextField();
        txtDestinatario = new javax.swing.JTextField();
        txtEndereco = new javax.swing.JTextField();
        lblAlteraCliente1 = new javax.swing.JLabel();
        lblTelefoneComercial1 = new javax.swing.JLabel();
        lblTelefoneComercial2 = new javax.swing.JLabel();
        lblTelefoneComercial3 = new javax.swing.JLabel();
        lblTelefoneComercial4 = new javax.swing.JLabel();
        lblTelefoneComercial5 = new javax.swing.JLabel();
        txtCEP = new javax.swing.JTextField();
        txtTelRes = new javax.swing.JTextField();
        txtComplemento = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtTipo = new javax.swing.JTextField();
        txtDescricao = new javax.swing.JTextField();
        txtNota = new javax.swing.JTextField();
        txtCidade = new javax.swing.JTextField();
        txtEstado = new javax.swing.JTextField();
        txtBairro = new javax.swing.JTextField();
        lblTelefoneComercial6 = new javax.swing.JLabel();
        txtCliente = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        lblCodigoCliente1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblCodigoCliente1.setText("Código");

        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        lblCEP1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblCEP1.setText("CEP");

        btnPesquisar.setText("Pesquisar");
        btnPesquisar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPesquisarActionPerformed(evt);
            }
        });

        lblNumero1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblNumero1.setText("Número");

        lblEstado1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblEstado1.setText("Estado");

        lblCidade1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblCidade1.setText("Cidade");

        txtNumero.setEditable(false);

        txtDestinatario.setEditable(false);

        txtEndereco.setEditable(false);

        lblAlteraCliente1.setFont(new java.awt.Font("Tahoma", 1, 15)); // NOI18N
        lblAlteraCliente1.setText("PESQUISAR ENTREGA");
        lblAlteraCliente1.setName(""); // NOI18N

        lblTelefoneComercial1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblTelefoneComercial1.setText("Telefone");

        lblTelefoneComercial2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblTelefoneComercial2.setText("Destinatario");

        lblTelefoneComercial3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblTelefoneComercial3.setText("Endereço");

        lblTelefoneComercial4.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblTelefoneComercial4.setText("Complemento");

        lblTelefoneComercial5.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblTelefoneComercial5.setText("Bairro");

        txtCEP.setEditable(false);

        txtTelRes.setEditable(false);

        txtComplemento.setEditable(false);

        jLabel2.setText("Tipo");

        jLabel3.setText("Nota Fiscal");

        jLabel4.setText("Descrição");

        txtTipo.setEditable(false);

        txtDescricao.setEditable(false);

        txtNota.setEditable(false);

        txtCidade.setEditable(false);

        txtEstado.setEditable(false);

        txtBairro.setEditable(false);

        lblTelefoneComercial6.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblTelefoneComercial6.setText("Cliente");

        txtCliente.setEditable(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblTelefoneComercial2)
                            .addComponent(lblTelefoneComercial3)
                            .addComponent(lblTelefoneComercial4)
                            .addComponent(lblCodigoCliente1))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(20, 20, 20)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(txtCodigo)
                                        .addGap(18, 18, 18)
                                        .addComponent(btnPesquisar)
                                        .addGap(18, 18, 18)
                                        .addComponent(lblTelefoneComercial6)
                                        .addGap(18, 18, 18)
                                        .addComponent(txtCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(txtEndereco)
                                    .addComponent(txtDestinatario)))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(182, 182, 182)
                                        .addComponent(lblAlteraCliente1))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(18, 18, 18)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addGroup(layout.createSequentialGroup()
                                                        .addGap(152, 152, 152)
                                                        .addComponent(jLabel4))
                                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                                        .addComponent(txtBairro, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addGap(51, 51, 51)
                                                        .addComponent(lblCidade1)))
                                                .addGap(26, 26, 26)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(txtDescricao, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(txtCidade, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(btnCancelar)))
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(txtComplemento, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(15, 15, 15)
                                                .addComponent(lblNumero1)
                                                .addGap(10, 10, 10)
                                                .addComponent(txtNumero, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(lblCEP1)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(txtCEP, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(18, 18, 18)
                                                .addComponent(lblTelefoneComercial1)))))
                                .addGap(0, 185, Short.MAX_VALUE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblTelefoneComercial5)
                            .addComponent(jLabel2))
                        .addGap(64, 64, 64)
                        .addComponent(txtTipo, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(lblEstado1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtNota, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE)
                            .addComponent(txtTelRes)
                            .addComponent(txtEstado))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblAlteraCliente1)
                .addGap(15, 15, 15)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCodigoCliente1)
                    .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnPesquisar)
                    .addComponent(lblTelefoneComercial6)
                    .addComponent(txtCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblTelefoneComercial2)
                    .addComponent(txtDestinatario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblTelefoneComercial3)
                    .addComponent(txtEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblTelefoneComercial1)
                        .addComponent(txtTelRes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblTelefoneComercial4)
                        .addComponent(txtNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblNumero1)
                        .addComponent(lblCEP1)
                        .addComponent(txtCEP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtComplemento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblEstado1)
                    .addComponent(lblTelefoneComercial5, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblCidade1)
                    .addComponent(txtCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel4)
                    .addComponent(jLabel3)
                    .addComponent(txtTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtDescricao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtNota, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27)
                .addComponent(btnCancelar)
                .addGap(26, 26, 26))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnPesquisarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPesquisarActionPerformed
        try{
            if (!txtCodigo.getText().equals("")) {
                ee = FachadaTranslog.getInstFachadaTranslog().consultaEntradaEntrega(Integer.parseInt(txtCodigo.getText()));
                if(ee != null){
                    txtCliente.setText(ee.getCodigoCliente().getCodigoPessoaJuridica().getRazaoSocial());
                    txtDestinatario.setText(ee.getDestinatario());
                    txtEndereco.setText(ee.getCodigoLogradouro().getEndereco());
                    txtComplemento.setText(ee.getCodigoLogradouro().getComplemento());
                    txtNumero.setText(ee.getCodigoLogradouro().getNumero());
                    txtCEP.setText(String.valueOf(ee.getCodigoLogradouro().getCep()));
                    txtTelRes.setText(String.valueOf(ee.getTelefoneDestinatario()));
                    txtBairro.setText(ee.getCodigoLogradouro().getCodigoBairro().getNome());
                    txtCidade.setText(ee.getCodigoLogradouro().getCodigoCidade().getNome());
                    txtEstado.setText(ee.getCodigoLogradouro().getCodigoEstado().getNome());
                    txtTipo.setText(ee.getVolumeEntregaList().get(0).getTipoVolume());
                    txtDescricao.setText(ee.getVolumeEntregaList().get(0).getDescricaoProdutoVolume());
                    txtNota.setText(ee.getVolumeEntregaList().get(0).getNumeroNotaFiscalVolume());
                } else{
                    JOptionPane.showMessageDialog(null, "Entrega não encontrada!");
                }
            } else{
                JOptionPane.showMessageDialog(null, "Dados Obrigatórios não Informados!");
            }
        }catch(Exception e){
            e.printStackTrace();
        }
    }//GEN-LAST:event_btnPesquisarActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        this.dispose();
        FrmMenuPrincipal form = new FrmMenuPrincipal();
        form.setVisible(true);
    }//GEN-LAST:event_btnCancelarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrmEntradaEntregaConsultar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmEntradaEntregaConsultar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmEntradaEntregaConsultar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmEntradaEntregaConsultar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FrmEntradaEntregaConsultar().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnPesquisar;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel lblAlteraCliente1;
    private javax.swing.JLabel lblCEP1;
    private javax.swing.JLabel lblCidade1;
    private javax.swing.JLabel lblCodigoCliente1;
    private javax.swing.JLabel lblEstado1;
    private javax.swing.JLabel lblNumero1;
    private javax.swing.JLabel lblTelefoneComercial1;
    private javax.swing.JLabel lblTelefoneComercial2;
    private javax.swing.JLabel lblTelefoneComercial3;
    private javax.swing.JLabel lblTelefoneComercial4;
    private javax.swing.JLabel lblTelefoneComercial5;
    private javax.swing.JLabel lblTelefoneComercial6;
    private javax.swing.JTextField txtBairro;
    private javax.swing.JTextField txtCEP;
    private javax.swing.JTextField txtCidade;
    private javax.swing.JTextField txtCliente;
    private javax.swing.JTextField txtCodigo;
    private javax.swing.JTextField txtComplemento;
    private javax.swing.JTextField txtDescricao;
    private javax.swing.JTextField txtDestinatario;
    private javax.swing.JTextField txtEndereco;
    private javax.swing.JTextField txtEstado;
    private javax.swing.JTextField txtNota;
    private javax.swing.JTextField txtNumero;
    private javax.swing.JTextField txtTelRes;
    private javax.swing.JTextField txtTipo;
    // End of variables declaration//GEN-END:variables
}
